package com.quanxiaoha.weblog.admin.controller;

import com.quanxiaoha.weblog.admin.model.vo.article.ReqVO.DeleteArticleReqVO;
import com.quanxiaoha.weblog.admin.model.vo.article.ReqVO.FindArticlePageListReqVO;
import com.quanxiaoha.weblog.admin.model.vo.article.ReqVO.PublishArticleReqVO;
import com.quanxiaoha.weblog.admin.model.vo.article.ReqVO.UpdateArticleReqVO;
import com.quanxiaoha.weblog.admin.service.AdminArticleService;
import com.quanxiaoha.weblog.common.aspect.ApiOperationLog;
import com.quanxiaoha.weblog.common.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin")
@Api(tags = "Admin文章模块")
public class AdminArticleController {


    @Autowired
    private AdminArticleService adminArticleService;

    @PostMapping("/article/save")
    @ApiOperation(value = "发布文章")
    @ApiOperationLog(description = "发布文章")
    public Response addArticle(@RequestBody PublishArticleReqVO publishArticleReqVO) {
        return adminArticleService.saveArticle(publishArticleReqVO);
    }


    @PostMapping("/article/delete")
    @ApiOperation(value = "删除文章")
    @ApiOperationLog(description = "删除文章")
    public Response delArticle(@RequestBody @Validated DeleteArticleReqVO deleteArticleReqVO) {
        return adminArticleService.delArticle(deleteArticleReqVO);
    }

    @PostMapping("/list")
    @ApiOperation(value = "查询文章分页数据")
    @ApiOperationLog(description = "查询文章分页数据")
    public Response getArticlePageList(@RequestBody FindArticlePageListReqVO findArticlePageListReqVO) {
        return adminArticleService.getArticlePageList(findArticlePageListReqVO);
    }

    @GetMapping("/article/detail/{id}")
    @ApiOperation(value = "根据id查询文章详情")
    @ApiOperationLog(description = "根据id查询文章详情")
    public Response getArticleDetailById(@PathVariable Long Id) {
        return adminArticleService.getArticleDetailById(Id);
    }


    @PostMapping("/article/update")
    @ApiOperation(value = "修改文章")
    @ApiOperationLog(description = "修改文章")
    public Response updateArticle(@RequestBody @Validated UpdateArticleReqVO updateArticleReqVO) {
        return adminArticleService.updateArticleById(updateArticleReqVO);
    }

}
